@extends('admin.layouts.master')
@section('css')
    <style>
        /*搜索框所在的区域*/
        .main_header{
            float: left;
            margin-top: 8px;
            width:100%;
            height: 100px;
            line-height: 100px;

        }
        .main_header_search{
            float: left;
            width: 200px;
            line-height: 100px;
        }
        .input_style{
            margin-top: 30px;
        }

        /*=====文件的导入区域=====*/
        .main_header_add{
            float: right;
            width: 460px;
            height: 100px;
            line-height: 100px;
            text-align: right;
        }
        .main_header_add a{
            color:#24a7f6;
            text-decoration:none;
        }
        /*RFID码仓库*/
        .rfid_db{
            margin-top: 32px;
            float: left;
            width: 120px;
            height: 40px;
            line-height: 40px;
            cursor: pointer;
            border-radius: 6px;
            background: #fff;
            text-align: center;
            margin-left:17px;
        }
        /*生成RFID*/
        .rfid_create{
            margin-top: 32px;
            float: left;
            width: 90px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
            border-radius: 6px;
            background: #fff;
            margin-left:17px;
        }
        .rfid_create:hover{
            box-shadow: 0 8px 12px rgba(0,0,0,0.2);
        }
        .rfid_db:hover{
            box-shadow: 0 8px 12px rgba(0,0,0,0.2);
        }
        /*RFID的字体*/
        .rfid_db span{
            color:#24a7f6;
            font-size: 18px;
        }

        .rfid_create span{
            color:#24a7f6;
            font-size: 18px;
        }
        /*文件导入的模块*/
        .add_box {
            float: left;
            width: 90px;
            height: 40px;
            margin-top: 32px;
            background: #fff;
            line-height: 40px;
            cursor: pointer;
            border-radius: 6px;
            margin-left:17px;
        }
        .add_box:hover{
            box-shadow: 0 8px 12px rgba(0,0,0,0.2);
        }

        .add_box img{
            float:left;
            margin-top:6px;
            margin-left:6px;
            width: 28px;
            height: 28px;
            line-height: 40px;
        }
        .add_box span{
            float: left;
            font-size:18px;
            margin-left: 8px;
            color:orange;
        }
        /*======主要内容区=====*/
        .main_form{
            float: left;
            width: 100%;
            height: 783px;
            background: #fff;
            border-radius: 10px;
            box-shadow: 0 8px 12px rgba(0,0,0,0.2);
        }
        .main_formlist{
            margin-top:30px;
        }
        .main_table{
            width: 94%;
            margin: 0 auto;
            border: 1px solid #B1B1B1;
        }
        .main_table tr{
            height: 15px;
            width: 100%;
        }
        .main_table tr th{
            text-align: center;
            line-height: 30px;
            height: 30px;
            font-size: 18px;
        }
        .main_table tr td{
            height: 42px;
            text-align: center;
        }
        /*laravel自带的分页样式*/
        .boot_fenye{
            margin: 0 auto;
            margin-top:2px;
            width: 94%;
            height: 55px;
        }
        .boot_page{
            float: right;

        }
        .boot_page_di{
            margin-left: 10px;
            float: left;
            text-align: right;
            font-size: 14px;
            height: 74px;
            line-height: 74px;

        }
        .boot_page_total{
            margin-left: 10px;
            float:left;
            text-align: right;
            font-size: 14px;
            height: 74px;
            line-height: 74px;


        }
        .boot_choose{
            margin-left:20px;
            float:right;
        }
        /*=========================*/
        /*======操作中的删除的样式===*/
        .formlist_handle a{
            font-size:16px;
            text-decoration: none;
        }
        .formlist_edit{
            color: #79C9F7;
        }
        .formlist_destory{
            color: red;
        }

        /*master引入后显示=====RFID管理*/
        .rfid_manage{
            background: #393F64;
        }
        /**********导入的样式**********/
        /*右边的样式*/
/*右边的样式*/
.main_box_right{
    /*text-align: right;*/
}
/*file样式的改变*/
.addfile{
    cursor: pointer;
    position: relative;
    display: inline-block;
    overflow: hidden;
    text-decoration: none;
    text-indent: 0;

}
.addfile input {
    position: absolute;
    font-size: 50px;
    right: 0;
    top: 0;
    opacity: 0;
}
    </style>
@endsection
@section('content')

    <div class="main_header clearfix">

        <div class="main_header_search clearfix">
            <form action="{{url('admin/rfidmanage/')}}" method="post">
            {{csrf_field()}}
            <div class="input-group input_style"  style="width:200px;">
                <input type="text" class="form-control" placeholder="输入RFID码" value="{{ $rfid or ''}}" name="rfid" style="height: 40px;"/>
                <span class="input-group-btn">
                <button type="submit" class="btn btn-info btn-search glyphicon glyphicon-search" style="margin-top:-62px;background: #3FB2F7;height: 40px; "></button>
               </span>
            </div>
            </form>
        </div>
        <div class="main_header_add clearfix">
            @if(Auth::guard('admin')->user()->checkPermission('rfid.warehouse'))
            <a href="{{url('/admin/rfidmanage/warehouse')}}">
            <div class="rfid_db">
                <span>RFID码仓库</span>
            </div>
            </a>
            @endif
            <div class="rfid_create">
                <span>生成RFID</span>
            </div>


            @if(Auth::guard('admin')->user()->checkPermission('rfid.create'))
            {{--<a href="javascript:void(0);" class="addfile">--}}
            <div class="add_box" onmouseover="this.style.cursor='hand'">
                <form action="" method="post" enctype="multipart/form-data" id="formlist">
                    {{csrf_field()}}
                    <input type="file" name="excel" value=""  id="fileinput" style="position: absolute;width: 90px;height: 40px;opacity: 0;
                          -ms-filter: 'alpha(opacity=0)';cursor:pointer;" onchange="fileupload()" multiple="multiple">
                <img src="{{asset('images/lodingin_icon.png')}}" alt="">
                <span onmouseover="this.style.cursor='hand'">导入</span>

                </form>
            </div>
            {{--</a>--}}
            @endif

                @if(Auth::guard('admin')->user()->checkPermission('rfid.create'))
                    <div class="add_box">
                        <span onclick="downloadExcel()" style="color: #24AFF8;">模板下载</span>
                    </div>
                @endif

        </div>
    </div>
    <div class="main_form clearfix">
        <!-- 表格 -->
        <div class="main_formlist">
            <table class="table table-bordered main_table">
                <tbody>
                <tr>
                    <th>商品序号</th>
                    <th>RFID码</th>
                    <th>商品编号</th>
                    <th>添加时间</th>
                    <th>出售状态</th>
                    <th>操作</th>
                </tr>
                @foreach($rfid_lists as $rfid_list)
                <tr>
                    <td>{{$rfid_list->goods_id}}</td>
                    <td>{{$rfid_list->rfid}}</td>
                    <td>{{$rfid_list->product_code}}</td>
                    <td>{{$rfid_list->created_at}}</td>
                    <td>
                        @if($rfid_list->state==0)
                            <span style="color:red;font-size: 16px;">未出售</span>
                            @else
                            <span style="font-size: 16px">已出售</span>
                        @endif
                    </td>
                    <td>
                        @if(Auth::guard('admin')->user()->checkPermission('rfid.destroy'))
                         <span class="formlist_handle">
                            <a href="{{url('/admin/rfidmanage/destroy',['rfid_id'=>$rfid_list->id])}}" class="formlist_destory"
                               onclick="if(confirm('确定删除吗?')==false) return false;layer.msg('删除成功');">
                                删除</a>
                        </span>
                            @endif
                    </td>
                </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        <!-- 分页 -->
        <div class="boot_fenye clearfix">
            <div class="boot_page">
                <div class="boot_page_di">第<span>{{ $page = isset($_GET['page'])?$_GET['page']:1}}</span>页
                </div>
                <div  class="boot_page_total">共<span>{{$total_page}}</span>页
                </div>
                <div class="boot_choose">
                    {{--appends是携带搜索分页的参数--}}
                    {{$rfid_lists->appends(['rfid'=>$rfid])->render()}}
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script>
        //模板下载
        function downloadExcel(){
            //获取服务器地址
            var host = location.host;
            //把excel发送出来,管理界面列表的下载
            var url = "http://"+ host +"/admin/rfidmanage/download";
            window.open(url);
        }
        //rfid仓库信息异步导入
        function fileupload(){
            $('#formlist').ajaxSubmit({
                url:'/admin/rfidmanage/import',
                dataType:'json',
                type:'post',
                data:$('#formlist').fieldSerialize(),
                success:function(res){
                    var input = document.getElementById('fileinput');
                    input.value='';
                    if (res.status == 0) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 1}, function () {
                            location.href = '/admin/rfidmanage';
                        });
                    }

                },
                error:function(xhr, type){
                    layer.msg('请检查导入的excel表格式是否正确');
                    var input = document.getElementById('fileinput');
                    input.value='';
                }
            });
        }
    </script>
@endsection
